package com.qianli.cashmama.product.facade.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by xuyang on 2017/7/19.
 */
public enum BusinessRuleEnum {

    QUOTA_CHECK("QUOTA_CHECK", "Quota check", BusinessRuleTypeEnum.QUOTA),                              // 额度检查
    ZHIMA_AUTH("ZHIMA_AUTH", "Zhima auth", BusinessRuleTypeEnum.RISK_INFO),                             // 芝麻认证
    PERSONAL_INFO("PERSONAL_INFO", "Personal information", BusinessRuleTypeEnum.RISK_INFO),             // 个人信息
    WORK_INFO("WORK_INFO", "Work info", BusinessRuleTypeEnum.RISK_INFO),                                // 工作信息
    CONTRACTS_INFO("CONTRACTS_INFO", "Contact information", BusinessRuleTypeEnum.RISK_INFO),            // 联系人信息
    BANK_INFO("BANK_INFO", "Bank info", BusinessRuleTypeEnum.RISK_INFO),                                // 收款银行卡
    FACE_RECOGNITION("FACE_RECOGNITION", "Face recognition", BusinessRuleTypeEnum.RISK_INFO),           // 运营商人脸识别
    TAOBAO_AUTH("TAOBAO_AUTH", "Taobao auth", BusinessRuleTypeEnum.RISK_INFO),                          // 淘宝认证
    JINGDONG_AUTH("JINGDONG_AUTH", "Jingdong auth", BusinessRuleTypeEnum.RISK_INFO),                    // 京东认证
    XUEXIN_AUTH("XUEXIN_AUTH", "Xuexin auth", BusinessRuleTypeEnum.RISK_INFO),                          // 学信网认证
    RISK_AUDIT("RISK_AUDIT", "Risk audit", BusinessRuleTypeEnum.AUDIT),                                 // 风控审核
    MANUAL_AUDIT("MANUAL_AUDIT", "Manual audit", BusinessRuleTypeEnum.AUDIT),                           // 人工审核
    PHONE_AUDIT("PHONE_AUDIT", "Phone audit", BusinessRuleTypeEnum.AUDIT),                              // 电话审核
    MANUAL_RECHECK("MANUAL_RECHECK", "Manual recheck", BusinessRuleTypeEnum.AUDIT),                     // 人工复核
    PHOTO_AUDIT("PHOTO_AUDIT", "Phone audit", BusinessRuleTypeEnum.AUDIT),                              // 照片复核
    QSYQ_TEMP_AUTH_RULE("QSYQ_TEMP_AUTH_RULE", "Qsyq temp auth rule", BusinessRuleTypeEnum.AUDIT),      // 轻松有钱临时信审规则
    SDZZ_TEMP_AUTH_RULE("SDZZ_TEMP_AUTH_RULE", "Sdzz temp auth rule", BusinessRuleTypeEnum.AUDIT);      // 闪电周转临时信审规则


    private String code;

    private String name;

    private BusinessRuleTypeEnum businessRuleTypeEnum;

    BusinessRuleEnum(String code, String name, BusinessRuleTypeEnum businessRuleTypeEnum) {
        this.code = code;
        this.name = name;
        this.businessRuleTypeEnum = businessRuleTypeEnum;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public BusinessRuleTypeEnum getBusinessRuleTypeEnum() {
        return businessRuleTypeEnum;
    }

    public static BusinessRuleEnum getByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        code = code.toUpperCase();
        return ProductRuleMapper.map.get(code);
    }

    private static class ProductRuleMapper {
        private static ConcurrentHashMap<String, BusinessRuleEnum> map = new ConcurrentHashMap<>();

        static {
            for (BusinessRuleEnum rule : BusinessRuleEnum.values()) {
                map.put(rule.getCode(), rule);
            }
        }
    }
}
